package de.medieninf.android.sensimg;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;

public class TouchEventButton extends Button {
	final static String TAG = "TouchEventButton";
	
	private KeyboardState keyboardState;
	
	public TouchEventButton(Context context) {
		super(context);
	}

	public TouchEventButton(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public TouchEventButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			if (keyboardState != null)
				keyboardState.onKeyDown(getText().toString().charAt(0));
			// Log.v(TAG, "onTouch event ACTION_DOWN" + getText().toString());
			break;
		case MotionEvent.ACTION_UP:
			if (keyboardState != null)
				keyboardState.onKeyUp(getText().toString().charAt(0));
			// Log.v(TAG, "onTouch event ACTION_UP" + getText().toString());
		}
		return super.onTouchEvent(event);
	}
	
	public void setKeyboardState(KeyboardState keyboardState) {
		this.keyboardState = keyboardState;
	}

}
